using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace DigitalTrainSuite.UserControls
{
	public partial class UserControlPlaceTrack : UserControl
	{

	#region private members

		private DataSetLayout.TrackRow track;
		private UserControlLayout layoutCanvas;
		private TrackType trackType;
		private static Bitmap[] trackBitmaps = {Properties.Resources.Straight, Properties.Resources.CurveRight, Properties.Resources.CurveLeft, 
			Properties.Resources.TurnoutStraightRight, Properties.Resources.TurnoutStraightLeft, Properties.Resources.TurnoutCurveRight,
			Properties.Resources.TurnoutCurveLeft, Properties.Resources.DoubleSlipSwitch, Properties.Resources.CurveRight, Properties.Resources.CurveLeft, 
			Properties.Resources.CurveRight, Properties.Resources.CurveLeft, Properties.Resources.CurveRight, Properties.Resources.CurveLeft, 
			Properties.Resources.Straight, Properties.Resources.Straight, Properties.Resources.Straight, Properties.Resources.Straight, 
			Properties.Resources.CurveRight, Properties.Resources.CurveLeft};
		private static string[] trackTexts = {"Straight", "Right", "Left", "Turnout Right", "Turnout Left", "Turnout Curve Right", "Turnout Curve Left", 
			"Double Slip Switch", "R1 Right", "R1 Left", "R2 Right", "R2 Left", "R3 Right", "R3 Left", "77.5mm Straight", "94mm Straight", "172mm Straight", 
			"188mm Straight", "437.5mm(R2) Right 24.3D", "437.5mm(R2) Left 24.3D"};
		private static string[] trackLabels = {"S", "R", "L", "TR", "TL", "TCR", "TCL", "DSS", "R1R", "R1L", "R2R", "R2L", "R3R", "R3L", "S77.5", "S94", "S172", 
			"S188", "24R", "24L"};

		#endregion

	#region public methods
		
		public UserControlPlaceTrack()
		{
			InitializeComponent();
		} 

		#endregion

	#region public properties

		public TrackType Type
		{
			get
			{
				return this.trackType;
			}
			set
			{
				this.trackType = value;
				if (this.trackType != TrackType.NoType)
				{
					this.pictureBox1.BackgroundImage = UserControlPlaceTrack.trackBitmaps[this.trackType.GetHashCode() - 1];
					this.labelPartName.Text = UserControlPlaceTrack.trackLabels[this.trackType.GetHashCode() - 1];
					this.toolTipPartInfo.SetToolTip(this.labelPartName, UserControlPlaceTrack.trackTexts[this.trackType.GetHashCode() - 1]);
					this.toolTipPartInfo.SetToolTip(this.pictureBox1, UserControlPlaceTrack.trackTexts[this.trackType.GetHashCode() - 1]);
					this.toolTipPartInfo.SetToolTip(this, UserControlPlaceTrack.trackTexts[this.trackType.GetHashCode() - 1]);
					this.labelPartName.Location = new Point((this.Width - this.labelPartName.Width) / 2, this.labelPartName.Location.Y);
				}
			}
		}

		public UserControlLayout LayoutCanvas
		{
			get { return this.layoutCanvas; }
			set 
			{
				this.layoutCanvas = value;
			}
		}

		#endregion

	#region private event handlers

		private void userControlPlaceTrack_Click(object sender, EventArgs e)
		{
			if (this.layoutCanvas != null)
			{
				this.track = layoutCanvas.Data.Track.NewTrackRow();
				switch (this.trackType)
				{
					case TrackType.CurveRightR1:
						this.track.radius = 360;
						this.track.angle = 30;
						break;
					case TrackType.CurveRightR2:
						this.track.radius = 437.5;
						this.track.angle = 30;
						break;
					case TrackType.CurveRightR3:
						this.track.radius = 515;
						this.track.angle = 30;
						break;
					case TrackType.CurveLeftR1:
						this.track.radius = 360;
						this.track.angle = 30;
						break;
					case TrackType.CurveLeftR2:
						this.track.radius = 437.5;
						this.track.angle = 30;
						break;
					case TrackType.CurveLeftR3:
						this.track.radius = 515;
						this.track.angle = 30;
						break;
					case TrackType.Straight172:
						this.track.length = 172;
						break;
					case TrackType.Straight188:
						this.track.length = 188;
						break;
					case TrackType.Straight94:
						this.track.length = 94;
						break;
					case TrackType.Straight775:
						this.track.length = 77.5;
						break;
					case TrackType.CurveRightR2_243:
						this.track.radius = 437.5;
						this.track.angle = 24.3;
						break;
					case TrackType.CurveLeftR2_243:
						this.track.radius = 437.5;
						this.track.angle = 24.3;
						break;
					default:
						break;
				}

				this.track.rotation = 0;
				this.track.type = this.trackType.GetHashCode();
				this.track.locationX = 0;
				this.track.locationY = 0;
				this.layoutCanvas.PlacingTrack = this.track;
				this.layoutCanvas.SelectedTool = Tools.PlacingTrack;
			}
			
		}

		#endregion

	}
}
